home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 013 / size.arc / SIZE.C next >
Encoding:
C/C++ Source or Header  |  1987-01-10  |  3.2 KB  |  125 lines

  1. #define LINT_ARGS 1
  2. #include <dos.h>
  3. #include <string.h>
  4. #include <memory.h>
  5. #include <stdio.h>
  6. #include <process.h>
  7.  
  8. main(argc, argv)
  9. int argc;
  10. char *argv[];
  11. {
  12.  
  13.     int i, j;
  14.     char file_name[80];
  15.     static int num_files = 0;    /* number of files checked */
  16.     char dta[128];
  17.     static long total = 0;        /* total size of all files */
  18.     static long size = 0;
  19.     static long tot_cl[] = {0, 0, 0, 0};    /* total clusters required */
  20.     static long max_cl[] = {315, 354, 316, 355};
  21.     static char over[]="**OVER**";        /* overflow message */
  22.     static char noover[]="        ";    /* no overflow */
  23.     char far *fn_fp;
  24.     char far *dta_fp;
  25.     char *ovmsg[4];
  26.     union REGS inregs;
  27.     union REGS outregs;
  28.     struct SREGS segregs;
  29.  
  30.     fn_fp = file_name;
  31.     dta_fp = dta;
  32.  
  33.     if(argc > 1) {
  34.         strcpy(file_name, argv[1]);
  35.         if(!strchr(file_name, '.')) {
  36.             if(file_name[strlen(file_name) - 1] != '\\')
  37.                 strcat(file_name, "\\*.*");
  38.             else
  39.                 strcat(file_name, "*.*");
  40.         }
  41.     } else
  42.         strcpy(file_name, "*.*");
  43.  
  44.     segread(&segregs);        /* read current value of seg regs */
  45.  
  46.     inregs.h.ah = 0x1A;        /* set current dta address */
  47.     segregs.ds = FP_SEG(dta_fp);
  48.     inregs.x.dx = FP_OFF(dta_fp);
  49.     intdosx(&inregs, &outregs, &segregs);
  50.  
  51.     segregs.ds = FP_SEG(fn_fp);
  52.     inregs.x.dx = FP_OFF(fn_fp);
  53.     inregs.x.cx = 0;
  54.     inregs.h.ah = 0x4E;
  55.  
  56.     intdosx(&inregs, &outregs, &segregs);    /* search for first file */
  57.  
  58.     if(outregs.x.cflag == 0) {        /* if file found */
  59.         ++num_files;
  60.         memcpy(&size, &dta[26], 4);
  61.         for(i = 0, j = 1; i < 4; i++, j *= 2)
  62.             tot_cl[i] += cluster(size, j);
  63.         total += size;
  64.  
  65.         do {                /* find rest of files */
  66.             inregs.h.ah = 0x4F;    /* find next file */
  67.             intdos(&inregs, &outregs);
  68.  
  69.             if(outregs.x.cflag == 0) {    /* if file found */
  70.                 ++num_files;
  71.                 memcpy(&size, &dta[26], 4);
  72.                 for(i = 0, j = 1; i < 4; i++, j *= 2)
  73.                     tot_cl[i] += cluster(size, j);
  74.                 total += size;
  75.             }
  76.         } while (outregs.x.cflag == 0);
  77.     }
  78.  
  79.     printf("\n\nNOTE:  FULL PATHNAMES AND/OR FILENAMES MAY BE USED");
  80.     printf(" AS ARGUMENT ON PROGRAM LINE");
  81.     printf("\n\n\tNumber of files = %d     Total size = %ld bytes",
  82.         num_files, total);
  83.  
  84.     printf("\n\n\n       ");
  85.     printf("TOTAL STORAGE REQUIRED IN BYTES FOR THE FOLLOWING DISKS");
  86.     printf("\n\n   160K SS     180K SS     320K DS     360K DS     ");
  87.     printf("10 MEG     20+MEG");
  88.     printf("\n   floppy      floppy      floppy      floppy       ");
  89.     printf("hard       hard");
  90.     printf("\n\n  %8ld    %8ld    %8ld    %8ld   %8ld   %8ld",
  91.         tot_cl[0] * 512L, tot_cl[0] * 512L, tot_cl[1] * 1024L,
  92.         tot_cl[1] * 1024L, tot_cl[3] * 4096L, tot_cl[2] * 2048L);
  93.     for(i = 0; i < 2; i++)
  94.         if(tot_cl[0] > max_cl[i])
  95.             ovmsg[i] = over;
  96.         else
  97.             ovmsg[i] = noover;
  98.     for(; i < 4; i++)
  99.         if(tot_cl[1] > max_cl[i])
  100.             ovmsg[i] = over;
  101.         else
  102.             ovmsg[i] = noover;
  103.     printf("\n  %s    %s    %s    %s\n\n", ovmsg[0], ovmsg[1], ovmsg[2],
  104.         ovmsg[3]);
  105.  
  106.     exit(0);
  107.  
  108. }
  109.  
  110. cluster(file_size, num_sec)
  111. long file_size;
  112. int num_sec;
  113. {
  114.  
  115.     int num_clust;        /* number of clusters required */
  116.  
  117.     num_sec *= 512;        /* number of bytes per cluster */
  118.     num_clust = file_size / (long)num_sec;
  119.     if(file_size > ((long)num_sec * (long)num_clust))
  120.         ++num_clust;
  121.  
  122.     return(num_clust);
  123.  
  124. }
  125.